package com.finance.services.util;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 *
 * @author Visual556
 */
@Service(value = Util.NAME)
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class Util {

    public static final String NAME = "util";
    
    public boolean check(List list) {
        return list != null && !list.isEmpty();
    }

    public boolean check(Object obj) {
        return obj != null;
    }

    public boolean check(String str) {
        return str != null && !str.isEmpty();
    }

    public List safe(List list) {
        return list == null ? Collections.EMPTY_LIST : list;
    }

    public String dateToString(Date date, String pattern) {
        if (pattern == null || pattern.equals("")) {
            pattern = "dd/MM/yyyy";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
}
